
const layout = {
  state: {
    activeId: '',
    elementList: []
  },
  // 写入
  mutations: {
    SET_ACTIVE_ID(state, data) {
      state.activeId = data;
    },
    SET_ELEMENT_LIST(state, data) {
      state.elementList = data;
    },
    UPDATE_ELEMENT_LIST(state, data) {
      state.elementList.push(data);
    },
    DELETE_ELEMENT(state, id) {
      state.elementList = state.elementList.filter(item => item.id !== id);
    }
  },
  // 外部操作
  actions: {
    setActiveId({ commit }, activeId) {
      commit('SET_ACTIVE_ID', activeId);
    },
    setElementList({ commit }, elementList) {
      commit('SET_ELEMENT_LIST', elementList);
    },
    updateElementList({ commit }, item) {
      commit('UPDATE_ELEMENT_LIST', item);
    },
    delElement({ commit }, id) {
      commit('DELETE_ELEMENT', id);
    },
  }
}
export default layout;